﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.DtoModel.Ms;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Domain.Repository.Implement.Ms
{
    public class MsProjectStandardMeasureItemRepository : BaseRepository<MsProjectStandardMeasureItem>, IMsProjectStandardMeasureItemRepository
    {
        public async Task<List<MsProjectStandardMeasureItem>> GetList(MsProjectStandardMeasureItemCondition condition)
        {
            return await (
       from h in Db.MsProjectStandardMeasureItems
       where h.ProjectStandardId == condition.ProjectStandardId && h.ProjectGuid == condition.ProjectGuid
       select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        public async Task<List<MsProjectStandardMeasureItem>> GetTemplateList()
        {
            return await (
                from h in Db.MsProjectStandardMeasureItems
                where h.ProjectGuid == new System.Guid()
                select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        public async Task<List<MsProjectStandardMeasureItem>> GetDataByProjects(Guid[] rpoejctGuid)
        {
            return await (
             from h in Db.MsProjectStandardMeasureItems
             where rpoejctGuid.Contains(h.ProjectGuid)
             select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        /// <summary>
        /// 根据项目阶段Id过滤
        /// </summary>
        /// <param name="rpoejctGuid">项目Id</param>
        /// <param name="excludeStandard">过滤项目阶段Id</param>
        /// <returns></returns>
        public async Task<List<MsProjectStandardMeasureItem>> GetDataByProjectsWithStandardId(Guid[] rpoejctGuid, Guid excludeStandard)
        {
            return await (
             from h in Db.MsProjectStandardMeasureItems
             where rpoejctGuid.Contains(h.ProjectGuid) && (h.ProjectStandardId != excludeStandard || excludeStandard == Guid.Empty)
             select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }
    }
}